<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button class="set">创建</button>
  <button class="get">获取</button>
</body>
<script>
  var setBtn = document.querySelector('.set');
  var getBtn = document.querySelector('.get');

  var date = new Date();
  date.setDate(date.getDate() + 7);

  setBtn.onclick = function () {

    var user = 'a123456';
    var pwd = '123456';
    var phone = '18371244604';
    var email = '2337808807@qq.com';

    document.cookie = 'user=' + user + ';expires=' + date.toUTCString();
    document.cookie = 'pwd=' + pwd + ';expires=' + date.toUTCString();
    document.cookie = 'phone=' + phone + ';expires=' + date.toUTCString();
    document.cookie = 'email=' + email + ';expires=' + date.toUTCString();


  }

  var arr = {};
  getBtn.onclick = function () {
    // console.log(document.cookie);
    var cookie = document.cookie;
    // console.log(cookie);
    if (cookie) {
      var list = cookie.split('; ')
      // console.log(list);
      for (i = 0; i < list.length; i++) {
        var item = list[i];
        // console.log(item);
        var name = item.split('=')[0];
        var key = item.split('=')[1];
        arr[name] = key;
      }

      console.log(arr);
    }

  }

</script>

</html>